#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QMap>

class Server : public QObject
{
    Q_OBJECT
private:
    explicit Server(QObject *parent = nullptr);

public:
    static Server* getInstance();
    void   setHost(const QString &host);

signals:
    void requestStudentIdSuccessed(const QString braceletSn, qint64 studentId);
    void requestStudentIdFailed( int error, const QString errorString);

    void pushScoreSuccessed(qint64 studentId);
    void pushScoreFailed(int error,  const QString errorString);

public slots:
    void requestStudentId(const QString &braceletSn);

    void pushScore(const QString &hardwareSn, const qint64 &studentId, int score);


private slots:
    void handleBraceletReply();
    void handleScoreReply();

    void handleReplyError(QNetworkReply::NetworkError code);


private:
    static Server * m_inst;

    QString m_host;
    QNetworkAccessManager   *m_net;


//    void handleBraceletReply(QNetworkReply *reply);
//    void handleScoreReply(QNetworkReply *reply);

    //QMap<QString, QNetworkReply*>  m_mapper;
};

#endif // SERVER_H
